#include<vector>
using namespace std;

class Solution {
private:
    int count(int num) {
        int res = 0;
        while (num>0) {
            if((num&1)==1)
                ++res;
            num >>= 1;
        }
        return res;
    }

   int sum(int num) {
        int res = 0;
        int index = 0;
        while (num > 0) {
            ++index;
            if ((num & 1) == 1)
                res += index;
            num >>= 1;
        }
        return res;
    }

   vector<int> getVec(int num) {
       vector<int> res;
       int index = 0;
       while (num > 0) {
           ++index;
           if ((num & 1) == 1) 
               res.push_back(index);
           num >>= 1;
       }
       return res;
   }

public:
    vector<vector<int>> combinationSum3(int k, int n) {
        vector<vector<int>> res;
        for (int i = 0; i < 512; ++i) {
            if (count(i) == k&& sum(i)==n) {
                res.push_back(getVec(i));
            }
        }
        return res;
    }
};